<script>
import {
  aboutme
} from "@/router.js"
import {
  getPaltFrom,
  addVistorInfo
} from "@/common/paltform.js"
import {getClientInfo} from "@/common/util.js"
import FingerprintJS from '@fingerprintjs/fingerprintjs'

export default {
  globalData: {
    paltform: ""
  },
  data() {
    return {
      first: true
    }
  },
  onLaunch: function () {
    console.log('App Launch');
    this.getOnLingFlag()
    addVistorInfo()
    // getClientInfo()
    this.getUniqueCode()
    //初始化全局平台信息
    if (getApp() && getApp().globalData) getApp().globalData.paltform = getPaltFrom()
  },
  onShow: function () {
    console.log('App Show');
    // #ifdef APP-PLUS
    var args = plus.runtime.arguments;
    if (args && args.indexOf("fromH5") != -1 && this.first) {
      uni.showToast({
        title: "从H5跳转过来",
        icon: 'none'
      })
      uni.navigateTo({
        url: aboutme
      })
      this.first = false
    }
    // #endif
  },
  onHide: function () {
    console.log('App Hide');
  },
  methods: {
    //获取设备唯一标识
    getUniqueCode(){
      FingerprintJS.load().then(fp => {
        fp.get().then(result => {
          const clientId = result.visitorId;
          console.log('获取设备唯一标识：',clientId);
          // debugger
          uni.setStorageSync('mClientId', clientId)
        });
      });
    },
    getOnLingFlag() {
      uniCloud.callFunction({
        name: 'database',
        data: {
          collection: 'config',
          type: 'doc',
          docId: '5f744f20c984090001d9d1a3'
        }
      }).then((res) => {
        console.log("getOnLingFlag", res)
        if (res.result.data && res.result.data.length > 0) {
          let result = res.result.data[0]
          let onling = result.onling
          console.log("getOnLingFlag", onling)
          uni.setStorageSync('onling', onling)
        }
      })
    }
  }
};
</script>

<style>
@import "./common/css/comm.css";
@import "./common/css/common.css";
@import "./common/css/font-awesome.css";
@import './common/css/weui.css';
@import './common/css/openai.css';

/* 解决头条小程序组件内引入字体不生效的问题 */
/* #ifdef MP-TOUTIAO */
@font-face {
  font-family: uniicons;
  src: url('/static/uni.ttf');
}

/* #endif */
.color-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, 75px);
  /** 平铺宽度为50px的单元格 */
  grid-template-rows: 75px;
  /** 设置高度为50px */
  grid-auto-rows: 75px;
  /** 当容易高度不够时，多余的组件高度将怎么分配，默认的高度由单元格内容决定 */
  justify-content: center;
  /** 水平居中  */
  grid-gap: 10 rpx;
  /** 水平和垂直间距为10rpx*/
  padding: 10 rpx;
  background: white;
  border-radius: 5 rpx;
}
</style>
